package com.zx.framework.web.service;

import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.async.DeferredResult;

@Service("aysncService")
@EnableScheduling
public class AysncService {
	
	private DeferredResult<String> deferredResult;
	
    public DeferredResult<String> getAsyncUpdate() {
        deferredResult = new DeferredResult<String>();
        return deferredResult;
    }

    @Scheduled(fixedDelay = 5000)
    public void refresh() {
        if (deferredResult != null) {
    		deferredResult.setResult(new Long(System.currentTimeMillis())
            .toString());
        }
    }
}
